﻿using DTM.Core.Utils;
using DTM.Model;
using System;
using System.Collections.Generic;

namespace DTM.Repository
{
    /// <summary>
    /// Class <see cref="PlayerRepository"/> declare player repository.
    /// </summary>
    internal class PlayerRepository : Repository<Player>, IPlayerRepository
    {
        #region Constructors

        /// <summary>
        /// Class <see cref="PlayerRepository" /> constructor.
        /// </summary>
        /// <param name="context">Database context.</param>
        public PlayerRepository(DatabaseEntities context)
            : base(context)
        {
        }

        #endregion Constructors

        #region Methods

        /// <summary>
        /// Returns all players.
        /// </summary>
        /// <returns></returns>
        public new IEnumerable<IPlayer> GetAll()
        {
            return base.GetAll();
        }

        /// <summary>
        /// Inserts new plater.
        /// </summary>
        /// <param name="player">Player to insert.</param>
        /// <returns></returns>
        public IPlayer Insert(IPlayer player)
        {
            Validate.NotNull<ArgumentNullException>(player, "player");
            var entity = new Player()
            {
                Email = player.Email,
                Name = player.Name,
                Surname = player.Surname
            };

            base.Insert(entity);
            return entity;
        }

        /// <summary>
        /// Update player.
        /// </summary>
        /// <param name="player">Player to update.</param>
        public void Update(IPlayer player)
        {
            Validate.NotNull<ArgumentNullException>(player, "player");
            var entity = GetById(player.Id);
            entity.Name = player.Name;
            entity.Surname = player.Surname;
            entity.Email = player.Email;
            base.Update(entity);
        }

        /// <summary>
        /// Delete player.
        /// </summary>
        /// <param name="playerid">PlayerId to delete.</param>
        public void Delete(int playerId)
        {
            base.Delete(playerId);
        }

        #endregion Methods
    }
}